package cn.itcast.user.conFig;

import cn.itcast.hmall.dto.common.ThreadLocalUtil;
import org.apache.commons.lang.StringUtils;
import org.springframework.stereotype.Component;
import org.springframework.web.servlet.HandlerInterceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
@Component
public class HandlerInterceptors implements HandlerInterceptor {
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) {
           //获取请求参数
        String authorization = request.getHeader("authorization");
        if (StringUtils.isBlank(authorization)) {
            return true;
        }
        ThreadLocalUtil.setUserId(Long.valueOf(authorization));
        return true;

    }
}
